﻿Imports System

Namespace System.Workflow.ComponentModel
    Friend Class CompositeActivityExecutor([Of] T As CompositeActivity)
        Inherits ActivityExecutor([Of] T)
        Implements ISupportWorkflowChanges
        ' Methods
        Protected Overrides Function Cancel(ByVal activity As T, ByVal executionContext As ActivityExecutionContext) As ActivityExecutionStatus
            Return MyBase.Cancel(activity, executionContext)
        End Function

        Protected Overrides Function Execute(ByVal activity As T, ByVal executionContext As ActivityExecutionContext) As ActivityExecutionStatus
            Return MyBase.Execute(activity, executionContext)
        End Function

        Private Sub System.Workflow.ComponentModel.ISupportWorkflowChanges.OnActivityAdded(ByVal executionContext As ActivityExecutionContext, ByVal addedActivity As Activity) Implements ISupportWorkflowChanges.OnActivityAdded
            If (executionContext Is Nothing) Then
                Throw New ArgumentNullException("executionContext")
            End If
            If (addedActivity Is Nothing) Then
                Throw New ArgumentNullException("addedActivity")
            End If
            Dim activity As CompositeActivity = [TryCast](executionContext.Activity,CompositeActivity)
            If (activity Is Nothing) Then
                Throw New ArgumentException("Error_InvalidActivityExecutionContext", "executionContext")
            End If
            activity.OnActivityChangeAdd(executionContext, addedActivity)
        End Sub

        Private Sub System.Workflow.ComponentModel.ISupportWorkflowChanges.OnActivityRemoved(ByVal executionContext As ActivityExecutionContext, ByVal removedActivity As Activity) Implements ISupportWorkflowChanges.OnActivityRemoved
            If (executionContext Is Nothing) Then
                Throw New ArgumentNullException("executionContext")
            End If
            If (removedActivity Is Nothing) Then
                Throw New ArgumentNullException("removedActivity")
            End If
            Dim activity As CompositeActivity = [TryCast](executionContext.Activity,CompositeActivity)
            If (activity Is Nothing) Then
                Throw New ArgumentException("Error_InvalidActivityExecutionContext", "executionContext")
            End If
            activity.OnActivityChangeRemove(executionContext, removedActivity)
        End Sub

        Private Sub System.Workflow.ComponentModel.ISupportWorkflowChanges.OnWorkflowChangesCompleted(ByVal executionContext As ActivityExecutionContext) Implements ISupportWorkflowChanges.OnWorkflowChangesCompleted
            If (executionContext Is Nothing) Then
                Throw New ArgumentNullException("executionContext")
            End If
            Dim activity As CompositeActivity = [TryCast](executionContext.Activity,CompositeActivity)
            If (activity Is Nothing) Then
                Throw New ArgumentException("Error_InvalidActivityExecutionContext", "executionContext")
            End If
            activity.OnWorkflowChangesCompleted(executionContext)
        End Sub

    End Class
End Namespace

